<?php session_start();
		  include('includes/header.php');
		  include("../includes/config.php"); 
		  
		  
		if($_POST['submit'] ){
			$allowedExts = array("jpg", "jpeg", "gif", "png");
			$extension = end(explode(".", $_FILES["file"]["name"]));
			if ((($_FILES["file"]["type"] == "image/gif")
			|| ($_FILES["file"]["type"] == "image/jpeg")
			|| ($_FILES["file"]["type"] == "image/pjpeg"))
			&& ($_FILES["file"]["size"] < 2000000)
			&& in_array($extension, $allowedExts))
			  {
			  if ($_FILES["file"]["error"] > 0)
				{
				echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
				}
			  else
				{
/* 				echo "Upload: " . $_FILES["file"]["name"] . "<br />";
				echo "Type: " . $_FILES["file"]["type"] . "<br />";
				echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
				echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; */
					$imgPath =  "http://". $_SERVER['SERVER_NAME'].	 "/vlieg/images/background-images/".$_FILES["file"]["name"];
					
					$maxO = mysql_fetch_array(mysql_query("select max(img_order) as imgOrder from `background-images`")); 
					$maxO = $maxO[imgOrder]  + 1;
					$price = mysql_real_escape_string($_POST['price']);
					$city = mysql_real_escape_string($_POST['city']);
					$text = mysql_real_escape_string($_POST['text']);
					
					$q = "insert into `background-images` (url,city,text,price,img_order) VALUES(
							 '$imgPath',
							 '$city',
							 '$text',
							 '$price',
							 '$maxO'
							 )";
							
						mysql_query($q) or die(mysql_error());
						
				
				  move_uploaded_file($_FILES["file"]["tmp_name"],
				  "../images/background-images/" . $_FILES["file"]["name"]);
				  echo "Gelukt";
				  
				}
			  }
			else
			  {
			  echo "Invalid file";
			  }
		  }
		  
?>

     <div  id="main" role="main" style="font-family:arial">
		<h1>Nieuwe achtergrondafbeelding toevoegen</h1>
			<form action="#" method="post"	enctype="multipart/form-data">
				<label for="file">Filename:</label>
				<input type="file" name="file" id="file" /> <br/>
					<label for="city">Stad:</label>
				<input type="text" name="city" id="city" /> <br/>
					<label for="text">Text:</label>
				<input type="text" name="text" id="text" /> <br/>
					<label for="text">Prijs:</label>
				<input type="text" name="price" id="price" /> <br/>
				<br />
				<input type="submit" name="submit" value="Submit" />
			</form>
     </div>

  
  
<?php include('includes/footer.php');?>